import axios, { AxiosPromise } from 'axios'
export interface logdata {
    projectName: string,
    logstoreName: string,
    from: Date,
    to: Date,
    query: string,
    topic?: string,
    line?: number,
    offset?: number,
    reverse?: boolean
}
const url = 'https://1335409291092281.cn-qingdao.fc.aliyuncs.com/2016-08-15/proxy/midway-all/getlogs/'

export default function FetchApi(body: logdata): AxiosPromise<any> {
    return new Promise(async (res, rej) => {
        let v = [1, 2, 3, 4, 5];
        const fun = axios(url, {
            method: 'post',
            data: body
        })
        for (const iterator of v) {
            try {
                const data = await fun
                if (data.data.errorMessage) {
                    if (iterator === 5) {
                        res(data)
                    }
                } else {
                    res(data)
                    return
                }
            } catch (e) {
                if (iterator === 5) {
                    rej(e)
                }
            }
        }
    })

}